package com.bs.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bs.model.Item;
import com.bs.service.IItemService;
import com.bs.vo.RestResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 说明：
 *
 * @author 琪
 * @since 2025/5/7 20:29
 */
@RestController
@RequestMapping("item")
@Api(tags = "商品接口")
public class ItemController {

    @Autowired
    private IItemService itemService;

    @PostMapping("add")
    @ApiOperation(value = "添加商品")
    public RestResultVo<Item> addItem(@RequestBody Item item) {
        itemService.save(item);
        return RestResultVo.ok(item);
    }

    @GetMapping("delete")
    @ApiOperation(value = "删除商品")
    public RestResultVo<Boolean> deleteItem(String id) {
        itemService.removeById(id);
        return RestResultVo.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "修改商品")
    public RestResultVo<Item> updateItem(@RequestBody Item item) {
        itemService.updateById(item);
        return RestResultVo.ok(item);
    }

    @GetMapping("query")
    @ApiOperation(value = "查询商品")
    public RestResultVo<Item> queryItem(String id) {
        Item item = itemService.getById(id);
        return RestResultVo.ok(item);
    }

    @PostMapping("list")
    @ApiOperation(value = "查询商品列表")
    public RestResultVo<List<Item>> listItem(@RequestBody Item item) {
        List<Item> list = itemService.list(new QueryWrapper<>(item));
        return RestResultVo.ok(list);
    }

}
